package com.yiwei.ydd.util;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.yiwei.ydd.R;

/**
 * Created by xsooy-pc on 18-10-11.
 */

public class NowStepDialog {
    private static int step = 0;

    public static void showStepOne(Activity context) {
        step = 0;
        final android.app.Dialog dialog = new android.app.Dialog(context,
                R.style.DialogStyle);
        View contentView = LayoutInflater.from(context)
                .inflate(R.layout.item_now_step_one, null);
        dialog.setContentView(contentView);
        dialog.setCancelable(false);
        ImageView imageView = (ImageView) contentView.findViewById(R.id.img_icon);
        contentView.findViewById(R.id.img_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (step == 0) {
                    imageView.setImageResource(R.mipmap.img_now_step_two);
                } else if (step == 1) {
                    imageView.setImageResource(R.mipmap.img_now_step_three);
                }
                step++;
                if (step == 3) {
                    imageView.setImageResource(0);
                    WindowManager.LayoutParams lp = context.getWindow().getAttributes();
                    lp.alpha = 1f;
                    context.getWindow().setAttributes(lp);
                    dialog.dismiss();
                }

            }
        });
        Window mWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = Util.getDisplayMetrics(context).heightPixels;
        } else {
            lp.width = Util.getDisplayMetrics(context).widthPixels;
        }
        mWindow.setAttributes(lp);
        dialog.show();
//
//
//        int layoutId = R.layout.item_now_step_one;
//
//
//        final PopupWindow popupWindow = new PopupWindow(contentView,
//                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
//
//        popupWindow.setTouchable(true);
//        popupWindow.setOutsideTouchable(false);
//
//        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
////        lp.alpha = 0f;
//        context.getWindow().setAttributes(lp);
//// 如果不设置PopupWindow的背景，有些版本就会出现一个问题：无论是点击外部区域还是Back键都无法dismiss弹框
//// 这里单独写一篇文章来分析
//        popupWindow.setBackgroundDrawable(new ColorDrawable());
//// 设置好参数之后再show
//        popupWindow.showAsDropDown(view);
//        return popupWindow;

    }


}
